import api from '../../../fetch/api'
export default {
  data() {
    return {
      bigImgPath: '',
      bindingCarCodeList:[]
    }
  },

  methods: {
    // 查看已绑定的车牌号
    checkBindingCarCode(row,modalName){
      let self = this
      self.bindingCarCodeList = []
      let params = {
          logicCardCode: row.carCode
      }
      API.fetchGet('monthTicketBill/getLogicCardCodeDetail',params).then(res=>{
        if(res.data){
            let data = res.data
            let obj = {
              carCode: data.logicCardCode, //车牌
            }
            if(data.openid){ //微信
              obj.cardCode = data.nickname //备注卡号
            }else{
              obj.cardCode = data.cardCode //备注卡号
            }
            self.bindingCarCodeList.push(obj)
        }
        self.toOpenModal(modalName)
      },err=>{})
    },
    getList() {
      let params = $.extend({}, this.searchParams, this.otherParams);
      if(params.hasOwnProperty("query_carCode")){
        delete params.query_carCode
        let attribStr = this.searchList[1].value
        params[attribStr] = this.searchList[1].inputVal
      }
      if (params) {
				for (let key in params) {
					if (params[key] === '' || params[key] === null) {
						delete params[key];
					}
				}
			}
      this.getItemList(params);
    },
    showBigImgModal(name, path) {
      this.bigImgPath = path;
      this.toOpenImgModal(name, path);
    },

    //获取列表
    getItemList(aparams) {
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      let setData = {};
      if (self.setData) {
        self.setData.searchList.forEach(element => {
          if (element.name == "query_time" && element.value != '') {
            setData["query_payTimeFrom"] = element.value.split(" - ")[0] + " 00:00:00";
            setData["query_payTimeTo"] = element.value.split(" - ")[1] + " 23:59:59";
          } else {
            setData[element.name] = element.value;
          }
        });
      }
      self.tbodysInfo = []
      params = $.extend(params, aparams, setData);
      api.fetchGet('/park/parkingBillDetail/list.do', params)
        .then(res => {
          let data = res.data,
            list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => {})
    },
    exportData() {
      let self = this;
      let theadsArr = []
      for (let i = 0; i < self.theadsInfo.length; i++) {
        if (self.theadsInfo[i].checked) {
          theadsArr.push(self.theadsInfo[i].prop)
        }
      }
      let params = {
        meterList: theadsArr.join(',')
      };
      let setData = {};
      if (self.setData) {
        self.setData.searchList.forEach(element => {
          if (element.name == "query_time" && element.value != '') {
            setData["query_payTimeFrom"] = element.value.split(" - ")[0] + " 00:00:00";
            setData["query_payTimeTo"] = element.value.split(" - ")[1] + " 23:59:59";
          } else {
            setData[element.name] = element.value;
          }
        });
      }
      params = $.extend({}, params, this.searchParams, this.otherParams, setData);
      if(params.hasOwnProperty("query_carCode")){
        delete params.query_carCode
        let attribStr = this.searchList[1].value
        params[attribStr] = this.searchList[1].inputVal
      }
      for(let key in params){
        if(params.hasOwnProperty(key)){
					if(!params[key]){
						delete params[key]
					}
        }
      }
      self.showDialog("确认导出该报表?", '', function () {
        self.toExportAsync('/park/parkingBillDetail/export.do', params)
      })
    },
    copyLink(obj) {
      let self = this;
      let ifx = 2; //标识aomp开票
      let openInvoiceUrl = obj.openUrlInvoice;
      let billCode = obj.billCode;
      let parkCode = obj.parkCode;
      let link = openInvoiceUrl + "?if=" + ifx + "&pc=" + parkCode + "&bc=" + billCode;
      //console.log(link);
      var aux = document.createElement("input");
      var content = link;
      aux.setAttribute("value", content);
      document.body.appendChild(aux);
      aux.select();
      document.execCommand("copy");
      document.body.removeChild(aux);
      self.showToast("复制链接成功", 1, 1500);
    }
  }
}
